﻿<CodeSnippetTabbed DocLink="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxDataGrid-1.CustomData">
    <CodeSnippetTabPage Text="Razor">@(@"<DxDataGrid T=""@WebApiOrder"" CustomData=""@LoadOrderData"" ShowFilterRow=""true"" CssClass=""mw-1100"">
    <Columns>
        <DxDataGridComboBoxColumn T=""@(WebApiCustomerLookup)"" TextFieldName=""Text"" ValueFieldName=""Value""
                                  CustomData=""@LoadCustomerData"" Field=""@nameof(WebApiOrder.CustomerID)"" Width=""300px"" />
        <DxDataGridDateEditColumn Field=""@nameof(WebApiOrder.OrderDate)"" Width=""180px"" />
        <DxDataGridSpinEditColumn Field=""@nameof(WebApiOrder.Freight)"" DisplayFormat=""c"" Width=""180px"" />
        <DxDataGridColumn Field=""@nameof(WebApiOrder.ShipCountry)"" Width=""210px"" />
        <DxDataGridComboBoxColumn T=""@(WebApiShipperLookup)"" TextFieldName=""Text"" ValueFieldName=""Value""
                                  CustomData=""@LoadShipmentData"" Field=""@nameof(WebApiOrder.ShipVia)"" Width=""220px"" />
    </Columns>
</DxDataGrid>
@code {
    [Inject] protected HttpClient Client { get; set; }

    protected async Task<LoadResult> LoadOrderData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken)
        => await LoadCustomData(""https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi/Orders"", options, cancellationToken);
    protected async Task<LoadResult> LoadCustomerData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken)
        => await LoadCustomData(""https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi/CustomersLookup"", options, cancellationToken);
    protected async Task<LoadResult> LoadShipmentData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken)
        => await LoadCustomData(""https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi/ShippersLookup"", options, cancellationToken);

    protected async Task<LoadResult> LoadCustomData(string dataEndpointUri, DataSourceLoadOptionsBase options, CancellationToken cancellationToken)
    {
        using var response = await Client.GetAsync(options.ConvertToGetRequestUri(dataEndpointUri), cancellationToken);
        response.EnsureSuccessStatusCode();
        using var responseStream = await response.Content.ReadAsStreamAsync();
        return await JsonSerializer.DeserializeAsync<LoadResult>(responseStream, cancellationToken: cancellationToken);
    }
}")</CodeSnippetTabPage>
</CodeSnippetTabbed>
